﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.GeometriesGraph.Index
{
	public class SweepLineSegment
	{
		public SweepLineSegment(Edge edge, int ptIndex)
		{
			this.edge = edge;
			this.ptIndex = ptIndex;
			this.pts = edge.Coordinates;
		}

		public double MinX
		{
			get
			{
				double x = this.pts[this.ptIndex].X;
				double x2 = this.pts[this.ptIndex + 1].X;
				if (x >= x2)
				{
					return x2;
				}
				return x;
			}
		}

		public double MaxX
		{
			get
			{
				double x = this.pts[this.ptIndex].X;
				double x2 = this.pts[this.ptIndex + 1].X;
				if (x <= x2)
				{
					return x2;
				}
				return x;
			}
		}

		public void ComputeIntersections(SweepLineSegment ss, SegmentIntersector si)
		{
			si.AddIntersections(this.edge, this.ptIndex, ss.edge, ss.ptIndex);
		}

		private readonly Edge edge;

		private readonly Coordinate[] pts;

		private readonly int ptIndex;
	}
}
